package com.wiringweb.exceptions;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

public class ExceptionTreeNode {

    private List<ExceptionHandlerObject> handlers = new ArrayList<>();
    private Class<? extends Throwable> exceptionClass;

    public ExceptionTreeNode(Class<? extends Throwable> exceptionClass) {
        this.exceptionClass = exceptionClass;
    }
    
    public void addHandler(Object controller, Method method) {
        ExceptionHandlerObject handler = new ExceptionHandlerObject(controller, method);
        handlers.add(handler);
    }

    public Class<? extends Throwable> getExceptionClass() {
        return exceptionClass;
    }

    public List<ExceptionHandlerObject> getHandlers() {
        return handlers;
    }

    @Override
    public String toString() {
        return exceptionClass.getName();
    }
    
    

    public static class ExceptionHandlerObject {

        private Object controller;
        private Method method;

        public ExceptionHandlerObject(Object controller, Method method) {
            this.controller = controller;
            this.method = method;
        }

        public Object getController() {
            return controller;
        }

        public Method getMethod() {
            return method;
        }
    }
}
